package com.fpost.action;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.fpost.constants.ActionConstants;

public class ChangeLangAction extends Action {
	
	private static Logger log = Logger.getLogger(ChangeLangAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String lang = request.getParameter("lang");		
		if (lang.equals("uk")) {
			request.getSession().setAttribute(Globals.LOCALE_KEY, new Locale("uk", ""));
			request.getSession().setAttribute(ActionConstants.CURRENT_LANG, "uk");  
		} else if (lang.equals("en")) {
			request.getSession().setAttribute(Globals.LOCALE_KEY, new Locale("en", ""));
			request.getSession().setAttribute(ActionConstants.CURRENT_LANG, "en");
		}				
		String currentPath = (String)request.getSession().getAttribute(ActionConstants.CURRENT_PATH);  
		return new ActionForward(currentPath, true); 
	}	
}
